<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex align-stretch benben-position-layout flex agriculturalToolrack_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex align-center justify-between flex-sub agriculturalToolrack_fd0_0'>
          <view class='flex align-center agriculturalToolrack_fd0_0_c0'>
            <!-- <text class='fu-iconfont2  agriculturalToolrack_fd0_0_c0_c0'>&#xE794;</text> -->
          </view>
          <view class='flex align-center'>
            <text class='agriculturalToolrack_fd0_0_c1_c0'>农具架</text>
          </view>
          <view class='flex align-center justify-end agriculturalToolrack_fd0_0_c0' @tap.stop="switchTypeFunc()">

          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout agriculturalToolrack_flex_1">
        <benben-select-diy ref="showSelectPopup1661497105968" class-name='flex flex-direction align-stretch flex'
          :items.sync="shoppingList" v-model="id" :select-all.sync="selectAll" default-type="aid"
          default-label="goods_name" :allow-cancel='true' type="checkbox" @change="changSelect" :disabled='false'
          :max-select="-1">
          <template v-for='(item,key0) in shoppingList'>
            <view v-if="item.isSelected" class='flex flex-direction align-stretch flex agriculturalToolrack_fd1_0_c0'
              :key="key0" @tap="$refs.showSelectPopup1661497105968.tapHandle(key0)">
              <view class='flex flex-wrap align-center agriculturalToolrack_fd1_0_c0_c0'>
                <image class='agriculturalToolrack_fd1_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"82.png"'></image>
                <image class='agriculturalToolrack_fd1_0_c0_c0_c1' mode="aspectFill" :src='item.goods_thumb'></image>
                <view class='flex flex-direction flex-wrap align-stretch flex-sub'>
                  <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c0'>{{item.goods_name}}</text>
                  <view class='flex flex-wrap align-center agriculturalToolrack_fd1_0_c0_c0_c2_c1'>
                    <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c1_c0' v-for="(itemC,indexC) in item.category_name"
                      v-if="item.category_name.length&& indexC<2">{{itemC}}</text>
                    <!-- <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c1_c1'>二级分类</text> -->
                  </view>
                  <view class='flex flex-wrap align-center justify-between'>
                    <view class='flex flex-wrap align-center'>
                      <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c0'>{{item.shop_price}}</text>
                      <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c1'>积分</text>
                    </view>
                    <view class='flex flex-wrap align-center' v-if=" item.num!=0">

                      <benben-flex-number-box
                        class-name='flex align-center justify-center flex agriculturalToolrack_numberBoxflexfd1_0_c0_c0_c2_c2_c1_c0'
                        input-class="agriculturalToolrack_numberBoxInputfd1_0_c0_c0_c2_c2_c1_c0" v-model="item.num"
                        :min="1" :step="1" :opacity="0.3">
                        <template #minus>
                          <image class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c1_c0_c0' mode="aspectFit"
                            :src='STATIC_URL+"39.png"'></image>
                        </template>
                        <template #plus>
                          <image class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c1_c0_c0' mode="aspectFit"
                            :src='STATIC_URL+"16.png"'></image>
                        </template>

                      </benben-flex-number-box>

                    </view>
                    <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c2' v-if=" item.num==0">已借完</text>
                  </view>
                </view>
                <view class="text-df base-text">{{item.no_notice}}</view>
              </view>

            </view>
            <view v-else class='flex flex-direction align-stretch flex agriculturalToolrack_fd1_0_c0' :key="key0"
              @tap="$refs.showSelectPopup1661497105968.tapHandle(key0)">
              <view class='flex flex-wrap align-center agriculturalToolrack_fd1_0_c1_c0'>
                <image class='agriculturalToolrack_fd1_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"83.png"'></image>
                <image class='agriculturalToolrack_fd1_0_c0_c0_c1' mode="aspectFill" :src='item.goods_thumb'></image>
                <view class='flex flex-direction flex-wrap align-stretch flex-sub'>
                  <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c0'>{{item.goods_name}}</text>
                  <view class='flex align-center agriculturalToolrack_fd1_0_c0_c0_c2_c1'>
                    <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c1_c0' v-for="(itemC,indexC) in item.category_name"
                      v-if="item.category_name.length&& indexC<2">{{itemC}}</text>
                    <!-- <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c1_c1'>二级分类</text> -->
                  </view>
                  <view class='flex flex-wrap align-center justify-between'>
                    <view class='flex flex-wrap align-center'>
                      <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c0'>{{item.shop_price || 0}}</text>
                      <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c1'>积分</text>
                    </view>
                    <view class='flex flex-wrap align-center' v-if=" item.num!=0">

                      <benben-flex-number-box @change="change(item)"
                        class-name='flex align-center justify-center flex  agriculturalToolrack_numberBoxflexfd1_0_c0_c0_c2_c2_c1_c0'
                        input-class="agriculturalToolrack_numberBoxInputfd1_0_c0_c0_c2_c2_c1_c0" v-model="item.num"
                        :min="1" :step="1" :opacity="0.3">
                        <template #minus>
                          <image class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c1_c0_c0' mode="aspectFit"
                            :src='STATIC_URL+"39.png"'></image>
                        </template>
                        <template #plus>
                          <image class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c1_c0_c0' mode="aspectFit"
                            :src='STATIC_URL+"16.png"'></image>
                        </template>

                      </benben-flex-number-box>

                    </view>
                    <text class='agriculturalToolrack_fd1_0_c0_c0_c2_c2_c2' v-if=" item.num==0">已借完</text>
                  </view>
                </view>
                <view class="text-df base-text">{{item.no_notice}}</view>
              </view>
            </view>
          </template></benben-select-diy>
      </view>

      <!---flex布局flex布局结束-->
      <view class="flex align-stretch benben-position-layout flex agriculturalToolrack_flex_2" v-if="isLogin">
        <button class='flex-sub agriculturalToolrack_fd2_del' @click="opnpop">删除</button>
        <button class='flex-sub agriculturalToolrack_fd2_0' @tap.stop="goOrder" data-type="navigateTo"
          :data-url="`/pages/agriculturalToolrack/oneclickOrdering/oneclickOrdering?id=${id}`">一键下单</button>

      </view>
      <view :style="{height: '160rpx'}"></view>
      <view class="" v-if="!isLogin" @tap.stop="handleJumpDiy" data-type="navigateTo"
        :data-url="`/pages/dlzc/login/login`">
        <view class="btnss">未登录，请先登录</view>
      </view>

    </view>
    <benben-popup v-model="popgoods" :mask="true" :mask-close-able="true" mode='center' :z-index='999'>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction align-center benben-flex-layout pickUp_flex_1">
        <text class='pickUp_fd1_0'>确认删除订单吗？</text>
        <view class='flex flex-wrap align-center'>
          <button class='pickUp_fd1_1_c0' @tap.stop="popgoods=false">取消</button>
          <button class='pickUp_fd1_1_c1' @tap.stop="delgoods()">确认</button>
        </view>
      </view>

      <!---flex布局flex布局结束-->

    </benben-popup>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        popgoods: false,
        "type": [{
          "name": "1",
          "value": "1",
          "image": ""
        }],
        "id": "",
        "selectAll": false,
        "status": "1",
        "number": 0,
        "number_max": 0,
        "number_min": 0,
        "shoppingList": []
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      isLogin() {
        return this.$store.state.token == '' ? false : true;
      }
    },
    watch: {},
    onLoad(options) {


    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      this.id = ''
      if (this.isLogin) {
        this.getshopListFunc()
      }
    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {
      this.getshopListFunc()
    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      changSelect() {
        let item = this.shoppingList.find(val => val.aid == this.id);
        console.log('22222', item)
        // if(item.no_notice){
        //   // this.$message.info(item.no_notice)
        //   // setTimeout(res=>{
        //   //   uni.navigateTo({
        //   //     url:`/pages/my/myDeposit/myDeposit`
        //   //   })
        //   // },500)
        // }
      },
      opnpop() {
        if (this.id == '') {
          this.$message.info('请选择农具')
          return;
        }
        this.popgoods = true
      },
      delgoods() {
        this.$api.post(global.apiUrls.post62b9854aa2c4e, {
          id: this.id
        }).then(res => {
          this.popgoods = false
          if (res.data.code == 1) {
            this.getshopListFunc()
          } else if (res.data.code == 0) {
            this.$message.info(res.data.msg);
          }
        })
      },
      goOrder() {
        console.log('2222', this.id)
        if (this.id == '') {
          this.$message.info('请选择农具')
          return;
        }
        this.$api.post(global.apiUrls.post62ba581c43bf9, {
          cart_ids: this.id
        }).then(res => {
          if (res.data.code == 1) {
            uni.navigateTo({
              url: `/pages/agriculturalToolrack/oneclickOrdering/oneclickOrdering?id=${this.id}`
            })
          } else if (res.data.code == 0) {
            this.$message.info(res.data.msg);
          } else if (res.data.code == '-111') {
            uni.navigateTo({
              url: `/pages/my/activateMembership/activateMembership`
            })
          } else if (res.data.code == '-222') {
            uni.navigateTo({
              url: `/pages/my/myDeposit/myDeposit`
            })
          }
        })

      },
      change(item) {
        console.log(item)
        this.$api.get(global.apiUrls.post62cf8cc5678f0, {
          aid: item.aid,
          // num: this.productDetails.sales_sum
          num: item.num
        }).then(res => {
          if (res.data.code == 1) {

          } else {
            // this.$message.info(res.data.msg);
          }
        })
      },
      //切换编辑状态
      switchTypeFunc() {
        if (this.status == '1') {
          this.status = '2';
          return
        }
        if (this.status == '2') {
          this.status = '1';
          return
        }
      },
      //详情页
      detailFunc() {
        this.$urouter.navigateTo(`/pages/homePages/farmtoolsDetail/farmtoolsDetail?id=${item.id}`);
      },
      //获取购物车列表
      async getshopListFunc() {
        //请求方法
        //数据验证

        let datashoppingList = await this.$api.get(global.apiUrls.post62b981f24a040, {

        });

        if (datashoppingList.data.code != 1) {
          this.$message.info(datashoppingList.data.msg);
          return
        }
        uni.stopPullDownRefresh()
        let infoshoppingList = datashoppingList.data;
        this.shoppingList = infoshoppingList.data
      }
    }
  };
</script>
<style lang="scss" scoped>
  .pickUp_flex_1 {
    background: rgba(255, 255, 255, 1);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 64rpx 74rpx 48rpx 74rpx;
  }

  .pickUp_fd1_0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx 0rpx 56rpx 0rpx;
  }

  .pickUp_fd1_1_c1 {
    background: #E63838;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    font-size: 28rpx;
    color: var(--benbenFontColor3);
    margin: 0rpx 0rpx 0rpx 12rpx;
    width: 176rpx;
    height: 72rpx;
  }

  .pickUp_fd1_1_c0 {
    background: #F8F8F8;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    font-size: 28rpx;
    color: var(--benbenFontColor0);
    margin: 0rpx 12rpx 0rpx 0rpx;
    width: 176rpx;
    height: 72rpx;
  }

  .btnss {
    width: 686rpx;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    border-radius: 44rpx;
    background-color: #e63838;
    color: #FFFFFF;
    margin: 100rpx auto 0 auto;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .agriculturalToolrack_flex_0 {
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-color: #FFFFFF;
  }

  .agriculturalToolrack_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
  }

  .agriculturalToolrack_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
  }

  .agriculturalToolrack_fd0_0_c0 {
    width: 180rpx;
  }

  .agriculturalToolrack_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
  }

  .agriculturalToolrack_flex_1 {
    padding: 24rpx 32rpx 0rpx 32rpx;
  }

  .agriculturalToolrack_fd1_0_c1_c0 {
    background: #FFFFFF;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 24rpx 32rpx 24rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c2_c2 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    margin: 0rpx 16rpx 0rpx auto;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c2_c1_c0_c0 {
    height: 48rpx;
    width: 48rpx;
  }

  ::v-deep .agriculturalToolrack_numberBoxInputfd1_0_c0_c0_c2_c2_c1_c0 {
    width: 60rpx;
    height: 50rpx;
    color: var(--benbenFontColor0);
    font-size: 28rpx;
    text-align: center;
  }

  ::v-deep .agriculturalToolrack_numberBoxflexfd1_0_c0_c0_c2_c2_c1_c0 {
    margin: 0rpx 0rpx 0rpx auto;
  }

  .base-text {
    color: rgba(230, 56, 56, 1);
    margin-left: 60rpx;
    margin-top: 20rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c1 {
    color: rgba(230, 56, 56, 1);
    font-size: 24rpx;
    font-weight: 700;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c2_c0_c0 {
    color: rgba(230, 56, 56, 1);
    font-size: 36rpx;
    font-weight: 700;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c1_c1 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c1_c0 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c1 {
    margin: 0rpx 0rpx 55rpx 0rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c2_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c1 {
    width: 200rpx;
    height: 200rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
    border-radius: 16rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0_c0 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 32rpx 0rpx 0rpx;
  }

  .agriculturalToolrack_fd1_0_c0_c0 {
    background: #FFFFFF;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 24rpx 32rpx 24rpx;
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .agriculturalToolrack_fd1_0_c0 {
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .agriculturalToolrack_flex_2 {
    background: #fff;
    width: 750rpx;
    height: 160rpx;
    overflow: hidden;
    z-index: 10;
    bottom: calc(0rpx + var(--window-bottom));
    background-size: 100% auto !important;
  }

  .agriculturalToolrack_fd2_0 {
    background: #E63838;
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    line-height: 100rpx;
    font-size: 32rpx;
    color: #fff;
    height: 100rpx;
    margin: 20rpx 24rpx 0rpx 24rpx;
  }

  .agriculturalToolrack_fd2_del {
    background: #f8f8f8;
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    line-height: 100rpx;
    font-size: 32rpx;
    color: #333;
    height: 100rpx;
    margin: 20rpx 24rpx 0rpx 24rpx;
  }
</style>